package org.roma.ninemen;

import java.text.ParseException;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

/**
 * 
 * @author Robin Weidelid and Mathias Larsson
 *
 */
public class SettingsActivity extends Activity {

	private EditText redBricks;
	private EditText blueBricks;
	private SharedPreferences pref;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		
		redBricks = (EditText) findViewById(R.id.numberOfRedBricks);
		blueBricks = (EditText) findViewById(R.id.numberOfBlueBricks);
		pref = getSharedPreferences(NineMenRoMaActivity.SHAREDPREF, MODE_PRIVATE);
		redBricks.setText(""+pref.getInt("numberOfRedBricks", 9));
		blueBricks.setText(""+pref.getInt("numberOfBlueBricks", 9));
	}

	
	public void saveSettings(View view){
		try{
			int numberOfRedBricks = Integer.parseInt(redBricks.getText().toString());
			int numberOfBlueBricks = Integer.parseInt(blueBricks.getText().toString());
		
			if( numberOfBlueBricks >= 4 && numberOfBlueBricks <= 9 && numberOfRedBricks >= 4 && numberOfRedBricks <= 9 ){
				 
				SharedPreferences.Editor editor = pref.edit();
				editor.putInt("numberOfRedBricks", numberOfRedBricks);
				editor.putInt("numberOfBlueBricks", numberOfBlueBricks);
				editor.commit();
				finish();
			}
		}
		catch(Exception e){
			Log.e("saveSettings Method error",e.toString());
		}
	}
	
	
	
}
